from appium import webdriver
from time import  sleep
from  selenium.webdriver.common.by import By
import time

desired_capabilities={
    'platformName':'Android',
    'platformVersion':'7.1.2',
    'deviceName':'127.0.0.1:62001',
    'appPackage':'com.gfeng.daydaycook',
    'appActivity':'com.gfeng.daydaycook.activity.WelcomeActivity',
    'noReset':True,
    'newCommandTimeout':60,
    'unicodeKeyboard':True,
    'resetKeyboard':True
}
screen_name=time.strftime('%Y%m%d_%H%M%S')
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_capabilities)
driver.implicitly_wait(30)

#定位器
jingxuan_locator=(By.XPATH,'//android.widget.TabWidget[@resource-id=\"android:id/tabs\"]/android.widget.RelativeLayout'
                           '[1]/android.widget.RelativeLayout[1]')
shequ_locator=(By.XPATH,"//android.widget.TabWidget[@resource-id=\"android:id/tabs\"]/android.widget.RelativeLayout[2]"
                        "/android.widget.RelativeLayout[1]")
push_locator=(By.XPATH,"//android.widget.ImageView[@resource-id=\"com.gfeng.daydaycook:id/iv_add\"]")
haowushe_locator=(By.XPATH,"//android.widget.TabWidget[@resource-id=\"android:id/tabs\"]/android.widget.RelativeLayout"
                           "[4]/android.widget.RelativeLayout[1]")
wode_locator=(By.XPATH,"//android.widget.RelativeLayout/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]")

uesrname_locator=(By.ID,"com.gfeng.daydaycook:id/telEdit")
password_locator=(By.ID,"com.gfeng.daydaycook:id/pwdEdit")
btn_login_locator=(By.ID,"com.gfeng.daydaycook:id/goButton")
back_locator=(By.ID,"com.gfeng.daydaycook:id/back")

window_size=driver.get_window_size()    #获取窗口大小
driver.swipe(window_size['width']/2,window_size['height']/3*2,window_size['width']/2,window_size['height']/3,1000)    #滑动（精选页面）
sleep(1)
driver.find_element(*shequ_locator).click()  #点击社区（切换到社区页面）
sleep(0.5)
driver.swipe(window_size['width']/2,window_size['height']/3*2,window_size['width']/2,window_size['height']/3,1000)    #滑动（上下）
sleep(1)
driver.swipe(window_size['width']/8*7,window_size['height']/2,window_size['width']/8,window_size['height']/2,1000)    #滑动（左右）
sleep(1)
driver.find_element(*push_locator).click()  #点击“+”号（切换到上传页面）
sleep(2)
driver.swipe(window_size['width']/2,window_size['height']/3*2,window_size['width']/2,window_size['height']/3,1000)    #滑动
sleep(5)
driver.find_element(*haowushe_locator).click()  #点击好物社（切换到好物社页面）
sleep(2)
driver.swipe(window_size['width']/2,window_size['height']/3*2,window_size['width']/2,window_size['height']/3,1000)    #滑动
sleep(2)